﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DLULearningNetworkModel;

namespace DLULearningNetwork.ViewModels
{
    public class ScheduleViewModel
    {
        public Guid CourseID { get; set; }
        public int Year { get; set; }
        public int Month { get; set; }
        public int DaysInMonth { get; set; }        
        public List<SeminarSchedule> SeminarSchedules { get; set; }
        public Course Course { get; set; }

        // 0: Sunday, 1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday
        public int FirstDayInMonth { get; set; }

        public ScheduleViewModel(Guid courseID, int year, int month)
        {
            this.CourseID = courseID;
            this.Year = year;
            this.Month = month;
            this.DaysInMonth = DateTime.DaysInMonth(year, month);
            DayOfWeek dow = new DateTime(year, month, 1).DayOfWeek;
            FirstDayInMonth = (int)dow;

            SeminarSchedules = SeminarSchedule.SelectByCourseID(courseID, year, month);
            this.Course = Course.GetCourseByID(this.CourseID);
        }

        public bool CheckCurDayHaveScheduleOrNot(int day)
        {
            if (day > this.DaysInMonth) return false;

            for (int i = 0; i < this.SeminarSchedules.Count; i++)
            {
                if (this.SeminarSchedules[i].Date_dt.Day == day)
                {
                    return true;
                }
            }

            return false;
        }

        public bool CheckCurDayIsValidOrNot(int day)
        {
            if (day > this.DaysInMonth) return false;

            DateTime startDate = this.Course.StartDate_dt;
            DateTime endDate = this.Course.EndDate_dt;
            DateTime curDate = new DateTime(this.Year, this.Month, day);
            return ((curDate.Date >= startDate.Date) && (curDate.Date <= endDate.Date));
        }
    }
}